from selenium.webdriver.common.by import By
from web_study.web_litemall_po.page_object.base_page import BasePage
from web_study.web_litemall_po.utils.log_utils import logger


# 登录页面
class LoginPage(BasePage):
    _BASE_URL = "http://litemall.hogwarts.ceshiren.com/#/login"

    __INPUT_USENAME = (By.XPATH, "//*[@name='username']")
    __INPUT_PASSWORD = (By.XPATH, "//*[@name='password']")
    __BTN_LOGIN = (By.XPATH, "//*[@class='el-button el-button--primary el-button--mini']")

    """登录页面：用户登录"""
    def login(self):
        logger.info("登录页面：用户登录")
        # 访问登录页
        logger.info("访问登录页")
        # 输入”用户名“
        # self.driver.find_element(By.XPATH, "//*[@name='username']").clear()
        # self.driver.find_element(By.XPATH, "//*[@name='username']").send_keys("mall123")
        self.do_send_keys("mall123", self.__INPUT_USENAME)
        # 输入”密码“
        # self.driver.find_element(By.XPATH, "//*[@name='password']").clear()
        # self.driver.find_element(By.XPATH, "//*[@name='password']").send_keys("mall123")
        self.do_send_keys("mall123", self.__INPUT_PASSWORD)
        # 点击”登录“按钮
        # self.driver.find_element(By.XPATH, "//*[@class='el-button el-button--primary el-button--mini']").click()
        self.do_find(self.__BTN_LOGIN).click()

        # ==》首页
        from web_study.web_litemall_po.page_object.home_page import HomePage
        # 跳转到下一个类
        return HomePage(self.driver)